package com.trafficsys.modules.owner.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.trafficsys.modules.entity.TravelCard;
import com.trafficsys.modules.owner.dao.EditCarDao;
import com.trafficsys.modules.owner.service.EditCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/api")
public class EditCarController {
    @Autowired
    EditCarService editCarService;

    /**
     * 车辆上户
     * http://localhost:8080/api/addCar
     * {"travelCarId":"123", "carNo":"渝A20310", "carClazz":"轿车", "cardId":"201", "userNature":"代步", "brandModel":"BWN", "vin":"C", "engineNo":"I3", "invalidDate":"2022-03-27 12:36:20", "fileNo":"7533", "state":"A"}
     *
     * @param travelCard
     * @return
     */
    @PostMapping(value = "/addCar", consumes = "application/json")
    public HashMap<String, Object> addCar(@RequestBody TravelCard travelCard) {
        return editCarService.addCar(travelCard);
    }

    /**
     * @param pageSize    每页多少条
     * @param currentPage 当前页
     * @return
     */
    @GetMapping("/page/list")
    public IPage<TravelCard> getByPage(@RequestParam Integer pageSize,
                                       @RequestParam Integer currentPage) {
        return editCarService.getByPage(pageSize, currentPage);
    }

    /**
     * 车辆过户 根据车牌号更改驾驶证号
     * http://localhost:8080/api/updateCar
     * {"travelCarId":"122", "carNo":"渝A20310" }
     *
     * @param travelCard
     * @return
     */
    @PutMapping(value = "/updateCar", consumes = "application/json")
    public HashMap<String, Object> updateCar(@RequestBody TravelCard travelCard) {
        return editCarService.updateCar(travelCard);
    }


    /**
     * http://localhost:8080/api/delCar/124
     *
     * @param travelCarId
     * @return
     */
    @DeleteMapping("/delCar/{travelCarId}")
    public HashMap<String, Object> delCar(@PathVariable String travelCarId) {
        return editCarService.delCar(travelCarId);
    }
}
